-- Prefan Access Controller
-- Derma Utilities

-- ################# Time saving DERMA functions @ Prefanatic
function CreateLabel( posx, posy, text, font, parent, name )

	local name = vgui.Create("DLabel", parent)
		name:SetText( text )
		name:SetFont( font )
		name:SizeToContents()

		if posx == "center" then posx = (parent:GetWide() / 2) - (name:GetWide() / 2) end
		name:SetPos( posx, posy )
		name:SetVisible(true)

	return name

end

function CreateDRAWLabel( text, font, posx, posy, color, alignx, aligny )

	draw.SimpleText( text, font, posx, posy, color, alignx, aligny )
	
end
	
	function CreatePanel( posx, posy, sizex, sizey, color, parent, name )

		if parent != nil then 
			name = vgui.Create("DPanel", parent)
		else
			name = vgui.Create("DPanel")
		end

			name:SetSize( sizex, sizey )
			name:SetPos( posx, posy )
			name.Paint = function()
				surface.SetDrawColor( color.r, color.g, color.b, color.a )
				surface.DrawRect( 0, 0, name:GetWide(), name:GetTall() )
			end
			
		return name
	
	end
	
	function CreateTextEntry( posx, posy, sizex, sizey, enter, onenter, parent, name )

		name = vgui.Create( "DTextEntry", parent )
		
		name:SetSize( sizex, sizey )
		if posx == "center" then posx = (parent:GetWide() / 2) - (name:GetWide() / 2) end
		name:SetPos( posx, posy )
		name:SetEnterAllowed( enter )
		
		name.OnEnter = onenter
		
		return name
	
	end
	
function PaintFrame( frame, col )

	frame.Paint = function()
		surface.SetDrawColor( col.r, col.g, col.b, col.a )
		surface.DrawRect( 0, 0, frame:GetWide(), frame:GetTall() )
	end
	
end

function CreateFrame( posx, posy, sizex, sizey, title, draggable, showclose, blur, parent, name )

	if parent != nil then
		name = vgui.Create("DFrame")
	else
		name = vgui.Create("DFrame")
	end
	
		name:SetPos(posx, posy)
		name:SetSize(sizex, sizey)
		name:SetTitle(title)
		name:SetVisible(true)
		name:SetDraggable(draggable)
		name:ShowCloseButton(showclose)
		name:SetBackgroundBlur(blur)
		
		name:MakePopup()
		
	return name
	
end

function CreateButton( posx, posy, sizex, sizey, text, onclick, hoverenter, hoverexit, parent, name )

	if parent != nil then 
		name = vgui.Create("DButton", parent)
	else
		name = vgui.Create("DButton")
	end
	
		name:SetText( text )
		name:SetSize( sizex, sizey )
		if posx == "center" then posx = (parent:GetWide() / 2) - (name:GetWide() / 2) end
		name:SetPos( posx, posy )
		
		name.DoClick = onclick
		name.OnCursorEntered = hoverenter
		name.OnCursorExited = hoverexit
		
	return name
	
end

function CreateListView( posx, posy, sizex, sizey, parent, name )
	
	if parent != nil then 
		name = vgui.Create("DListView", parent)
	else
		name = vgui.Create("DListView")
	end
	
		name:SetSize( sizex, sizey )
		if posx == "center" then posx = (parent:GetWide() / 2) - (name:GetWide() / 2) end
		name:SetPos( posx, posy )
		name:SetMultiSelect( false )
		
	return name
	
end

function CreateCheckBox( posx, posy, text, convar, value, parent, name )

	if parent != nil then 
		name = vgui.Create("DCheckBoxLabel", parent)
	else
		name = vgui.Create("DCheckBoxLabel")
	end
	
		name:SetPos( posx, posy )
		name:SetText( text )
		name:SetConVar( convar )
		name:SetValue( value )
		name:SizeToContents()
	
	return name
	
end
